﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BooksManagement
{
    
    class Means
    {
        private static readonly string conString = "server=.;database=Blogs;uid=sa;pwd=1218";
        /// <summary>
        /// 获得数据库数据的方法
        /// </summary>
        /// <param name="sql"></param>
        /// <returns></returns>
        public static DataTable GetTheData(string sql)
        {
            SqlConnection sqlconnection = new SqlConnection(conString);

            SqlDataAdapter DataAdapter = new SqlDataAdapter(sql, sqlconnection);

            DataTable dataTable = new DataTable();

            sqlconnection.Open();
            DataAdapter.Fill(dataTable);

            
            return dataTable;
        }
        /// <summary>
        /// 数据添加删除修改的方法
        /// </summary>
        /// <param name="sql"></param>
        /// <returns></returns>
        public static int AddorEditOrDeleteSave(string sql)
        {
            SqlConnection sqlConnection = new SqlConnection(conString);

            SqlCommand sqlCommand = new SqlCommand(sql, sqlConnection);

            sqlConnection.Open();
            return sqlCommand.ExecuteNonQuery();
        }

    }
}
